<template>
	<view class="page">
		<view class="flex benben-position-layout flex flex-wrap align-center personalInformation_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub personalInformation_fd0_0'>
				<view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  personalInformation_fd0_0_c0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">&#xE794;</text>
				</view>
				<text class='personalInformation_fd0_0_c1'>车辆管理</text>
				<view class='flex flex-wrap align-center personalInformation_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<u-sticky :offset-top="88+StatusBarRpx">
			<view class="search_view">
				<view class="tabs flex align-center">
					<view class="tabs_item" :class="tabs_id == 1 ? 'active_item' : ''" @tap.stop="selectTabs(1)">
						<view>已上线</view>
						<view v-if="tabs_id == 1" class="tabs_icon"></view>
					</view>
					<view class="tabs_item" :class="tabs_id == 5 ? 'active_item' : ''" @tap.stop="selectTabs(5)">
						<view>已下线</view>
						<view v-if="tabs_id == 5" class="tabs_icon"></view>
					</view>
				</view>
				<view class="search_input flex align-center">
					<image :src='STATIC_URL+"451.png"' mode="aspectFill"></image>
					<input v-model="keyword" class="input" type="text" placeholder="输入车牌号..."
						placeholder-style="font-size:30rpx;color:#999;" @confirm="getSearch">
				</view>
			</view>
		</u-sticky>
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#1A66FA"></u-loading>
			<view>加载中</view>
		</view>
		<template v-else>
			<view class="car_list">
				<view class="car_item" v-for="(item,index) in list" :key="index">
					<view class="car_top flex align-center">
						<view class="top_le">
							<view class="card_no">
								<view class="card_no_text flex align-center">
									<view>{{item.car_number}}</view>
									<view class="car_tag_1 flex align-center justify-center" v-if="item.type == 2">新能源
									</view>
									<view class="car_tag_2 flex align-center justify-center">{{item.model}}</view>
								</view>
							</view>
							<view class="label_list">
								<view class="label_item flex align-center justify-center">{{item.brand_name}}</view>
							</view>
						</view>
						<view class="top_ri">
							<u-lazy-load height="146" border-radius="16" class="car_img" :image="item.image"
								:loading-img="loadingImg" :error-img="errorImg"></u-lazy-load>
						</view>
					</view>
					<view class="car_ce flex align-center justify-between">
						<view class="">{{item.name}}</view>
						<view class="">{{item.store_name}}</view>
					</view>
					
					<view class="car_btm flex align-center justify-between">
						<view class="btm_le flex align-center">
							<view class="btm_le_item flex align-center">
								<view class="btm_le_item_week flex align-center justify-center">周中价：{{item.midweekList}}</view>
								<view class="btm_le_item_price">
									<text class="btm_le_item_price_1">￥</text>
									<text>{{Number(item.midweek_fee)}}</text>
								</view>
							</view>
							<view class="btm_le_item flex align-center">
								<view class="btm_le_item_week_ot flex align-center justify-center">周末价：{{item.weekendList}}</view>
								<view class="btm_le_item_price_ot">
									<text class="btm_le_item_price_1">￥</text>
									<text>{{Number(item.weekend_fee)}}</text>
								</view>
							</view>
						</view>
						<!-- <view class="btm_ri">
							<text class="btm_ri_1">押金：</text>
							<text class="btm_ri_2">¥</text>
							<text class="btm_ri_3">{{ item.deposit | frontPrice }}</text>
							<text class="btm_ri_4">{{ item.deposit | laterPrice }}</text>
						</view> -->
					</view>
					
					<view class="deposit_view flex align-center justify-between">
						<view class="deposit_text">
							<text class="deposit_text_1">车损押金：</text>
							<text class="deposit_text_2">¥</text>
							<text class="deposit_text_3">{{Number(item.deposit)}}</text>
						</view>
						<view class="deposit_text">
							<text class="deposit_text_1">违章押金：</text>
							<text class="deposit_text_2">¥</text>
							<text class="deposit_text_3">{{Number(item.violation_fee)}}</text>
						</view>
					</view>
					
					<view class="operation_view flex align-center justify-between">
						<view class="operation_1 flex align-center justify-center" @tap.stop="handleJumpDiy"
							data-type="navigateTo"
							:data-url="`/pages/index/inventoryCalendar/inventoryCalendar?car_id=${item.car_id}`">库存管理
						</view>
						<view class="operation_1 flex align-center justify-center" @tap.stop="adjustStore(item)">调门店
						</view>
						<view class="operation_1 flex align-center justify-center" v-if="item.status == 1"
							@tap.stop="offlineCar(item.id)">下线</view>
						<view class="operation_1 flex align-center justify-center" v-if="item.status == 5"
							@tap.stop="onlineCar(item.id)">上线</view>
						<view class="operation_1 flex align-center justify-center" @tap.stop="handleJumpDiy"
							data-type="navigateTo" :data-url="`/pages/index/vehicle/details?id=${item.id}`">
							<!-- <image :src='STATIC_URL+"479.png"' mode="aspectFill"></image>
							<text>分享</text> -->
							<text>完善信息</text>
						</view>
					</view>
				</view>
				<view class="loadmore" v-if="last_page > 1">
					<u-loadmore font-size="24" :status="status" :icon-type="iconType" :load-text="loadText" />
				</view>
			</view>
			<view class="noData" v-if="list.length == 0 && !isShow">
				<image :src='STATIC_URL+"no.png"'></image>
			</view>
		</template>

		<u-popup v-model="storeShow" mode="bottom" border-radius="32" :safe-area-inset-bottom="true">
			<view class="store_popup">
				<view class="popup_title flex align-center justify-between">
					<view class="">当前所属门店：{{old_store.store_name}}</view>
					<image @tap.stop="storeShow=false" :src='STATIC_URL+"232.png"' mode="aspectFill"></image>
				</view>
				<scroll-view scroll-y="true" class="store_list">
					<view class="store_item flex align-center" v-for="(item, index) in storeList" :key="index"
						@tap.stop="selectStore(item.id)">
						<image class="store_img" :src='item.image' mode="aspectFill"></image>
						<view class="store_text">
							<view class="store_name flex align-center">
								<view class="store_name_text">{{item.name}}</view>
								<!-- <image class="store_name_icon" :src='STATIC_URL+"435.png"' mode="aspectFill"></image> -->
							</view>
							<view class="store_address">{{item.address}}</view>
						</view>
						<image v-if="new_store_id == item.id" class="select_img" :src='STATIC_URL+"7.png"'
							mode="aspectFill"></image>
						<image v-else class="select_img" :src='STATIC_URL+"8.png"' mode="aspectFill"></image>
					</view>
				</scroll-view>

				<view class="store_btn flex align-center justify-center" @tap.stop="submitStore">确定</view>
			</view>
		</u-popup>

		<!-- <image class="add_car" :src='STATIC_URL+"458.png"' mode="aspectFill"></image> -->
	</view>
</template>
<script>
	import UploadImage from '@/common/utils/upload-image.js'
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},

		data() {
			return {
				"loadingImg": "",
				"errorImg": "",
				"imageUrl": "https://speed.zhongchuxing.com/gjdimages/476.png",
				"tabs_id": 1, //车辆状态1:空闲,2:在租,3:预留,4:维修,5:下架

				"keyword": "",
				"list": [],
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				"isShow": true,
				"storeShow": false,
				"storeList": [], // 门店列表
				"old_store": "",
				"new_store_id": "",
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			this.getStoreList();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getCarList();
		},
		onHide() {

		},
		onResize() {

		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getCarList();
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {

				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.getCarList();
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			// 获取门店列表  postStore
			getStoreList() {
				this.$api.post(global.apiUrls.postStore, {

				}).then(res => {
					if (res.data.code == 1) {
						this.storeList = res.data.data;
					} else {
						this.$message.info(res.data.info);
					}
				})
			},
			selectTabs(id) {
				this.tabs_id = id;
				this.page = 1;
				this.is_pull = true;
				this.isShow = true;
				this.getCarList();
			},
			// 获取车辆列表  postRealCar
			getCarList() {
				this.$api.post(global.apiUrls.postRealCar, {
					keyword: this.keyword,
					status: this.tabs_id,
					page: this.page,
					rows: 10
				}).then(res => {
					// console.log(res);
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 1) {
						this.last_page = res.data.data.totalPage;
						if (this.is_pull) {
							this.list = res.data.data.items;
						} else {
							this.list = this.list.concat(res.data.data.items);
						}
						if (this.list.length > 0) {
							this.list.forEach((item, index) => {
								item.midweekList = (this.numsToWeeks(item.midweek));
								item.weekendList = (this.numsToWeeks(item.weekend));
							})
						}
						console.log(this.list);
					} else {
						this.$message.info(res.data.info);
					}
				})
			},
			// 搜索
			getSearch() {
				this.page = 1;
				this.is_pull = true;
				this.isShow = true;
				this.getCarList();
			},
			// 车辆下线
			offlineCar(id) {
				this.$api.post(global.apiUrls.updateRealCar, {
					id: id,
					status: 5
				}).then(res => {
					this.$message.info(res.data.info);
					if (res.data.code == 1) {
						this.page = 1;
						this.is_pull = true;
						this.isShow = true;
						this.getCarList();
					}
				})
			},
			onlineCar(id) {
				this.$api.post(global.apiUrls.updateRealCar, {
					id: id,
					status: 1
				}).then(res => {
					this.$message.info(res.data.info);
					if (res.data.code == 1) {
						this.page = 1;
						this.is_pull = true;
						this.isShow = true;
						this.getCarList();
					}
				})
			},
			// 调整门店
			adjustStore(item) {
				this.old_store = item;
				this.storeShow = true;
			},
			selectStore(id) {
				this.new_store_id = id;
			},
			submitStore() {
				if (!this.new_store_id) {
					this.$message.info('请选择门店');
					return;
				}
				this.storeShow = false;
				this.$api.post(global.apiUrls.updateStore, {
					id: this.old_store.id,
					store_id: this.new_store_id
				}).then(res => {
					this.$message.info(res.data.info);
					if (res.data.code == 1) {
						this.new_store_id = "";
						this.page = 1;
						this.is_pull = true;
						this.isShow = true;
						this.getCarList();
					}
				})
			},
			numsToWeeks(str) {
				const weeks = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
				return str.split(',').map(v => weeks[v]).join(',');
			}
		}
	};
</script>
<style lang="scss" scoped>
	.add_car {
		width: 112rpx;
		height: 112rpx;
		position: fixed;
		right: 24rpx;
		bottom: 116rpx;
	}

	.store_popup {
		padding: 0 30rpx 30rpx;

		.popup_title {
			padding: 40rpx 0 30rpx 0;
			border-bottom: 1px solid #eee;
			font-weight: 600;
			font-size: 30rpx;
			color: #222222;

			image {
				width: 34rpx;
				height: 34rpx;
			}
		}

		.store_list {
			height: 600rpx !important;

			.store_item {
				padding: 30rpx 2rpx;

				.store_img {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
				}

				.store_text {
					flex: 1;
					margin: 0 24rpx;

					.store_name {
						.store_name_text {
							font-weight: 600;
							font-size: 28rpx;
							color: #222222;
						}

						.store_name_icon {
							width: 177rpx;
							height: 44rpx;
							margin-left: 12rpx;
						}
					}

					.store_address {
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
						margin-top: 4rpx;
					}
				}

				.select_img {
					width: 32rpx;
					height: 32rpx;
				}
			}
		}

		.store_btn {
			width: 690rpx;
			height: 84rpx;
			background: #1A66FA;
			border-radius: 60rpx 60rpx;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
			margin-top: 30rpx;
		}
	}

	.car_list {
		padding: 0 24rpx 24rpx;

		.car_item {
			margin-top: 16rpx;
			background: #fff;
			border-radius: 16rpx;
			padding-bottom: 32rpx;

			.car_top {
				padding-left: 24rpx;

				.top_le {
					width: calc(100% - 222rpx);

					.card_no {
						.card_no_text {
							font-weight: bold;
							font-size: 36rpx;
							color: #222222;
						}

						.car_tag_1 {
							width: 100rpx;
							height: 40rpx;
							background: url(https://speed.zhongchuxing.com/gjdimages/477.png) no-repeat;
							background-size: 100% 100%;
							font-weight: 400;
							font-size: 22rpx;
							color: #FFFFFF;
							margin-left: 10rpx;
						}

						.car_tag_2 {
							width: 72rpx;
							height: 40rpx;
							background: url(https://speed.zhongchuxing.com/gjdimages/478.png) no-repeat;
							background-size: 100% 100%;
							font-weight: 400;
							font-size: 22rpx;
							color: #FFFFFF;
							margin-left: 10rpx;
						}
					}

					.label_list {
						margin-top: 14rpx;
						overflow: hidden;

						.label_item {
							float: left;
							background: #E9EEFF;
							padding: 4rpx 20rpx;
							margin: 0 12rpx 0rpx 0;
							border-radius: 8rpx;
							font-weight: 400;
							font-size: 22rpx;
							color: #1A66FA;
						}
					}
				}

				.top_ri {
					width: 222rpx;
					height: 146rpx;

					.car_img {
						width: 222rpx;
						height: 146rpx;
					}

					/deep/.u-lazy-item {
						width: 222rpx !important;
						height: 146rpx !important;
					}
				}
			}

			.car_ce {
				margin: 8rpx 24rpx 0;
				background: #F6F7FB;
				border-radius: 16rpx;
				padding: 20rpx 24rpx;
				font-weight: 400;
				font-size: 28rpx;
				color: #222222;
			}
			
			.deposit_view {
				margin: 0 24rpx;
				.deposit_text {
					.deposit_text_1 {
						font-size: 24rpx;
					}
					.deposit_text_2 {
						font-size: 24rpx;
					}
					.deposit_text_3 {
						font-size: 24rpx;
						font-weight: bold;
					}
				}
			}

			.car_btm {
				margin: 24rpx 24rpx 0;

				.btm_le {
					flex-wrap: wrap;

					.btm_le_item {
						border-radius: 16rpx;
						border: 2rpx solid #DFE9FF;
						margin-right: 18rpx;
						margin-bottom: 16rpx;

						.btm_le_item_week {
							font-weight: 500;
							font-size: 22rpx;
							color: #1A66FA;
							// width: 70rpx;
							height: 42rpx;
							padding: 0 20rpx;
							background: #DFE9FF;
							border-radius: 16rpx 0 30rpx 16rpx;
						}

						.btm_le_item_price {
							color: #1A66FA;
							font-weight: bold;
							font-size: 22rpx;
							padding: 0 8rpx;

						}

						.btm_le_item_week_ot {
							font-weight: 500;
							font-size: 22rpx;
							color: #FF532E;
							// width: 70rpx;
							height: 42rpx;
							padding: 0 20rpx;
							background: #FFEBE7;
							border-radius: 16rpx 0 30rpx 16rpx;
						}

						.btm_le_item_price_ot {
							color: #FF532E;
							font-weight: bold;
							font-size: 22rpx;
							padding: 0 8rpx;
						}

						.btm_le_item_price_1 {
							font-size: 24rpx;
						}
					}
					.btm_le_item:nth-child(4n + 4) {
						margin-right: 0;
					}
				}

				.btm_ri {
					color: #222222;

					.btm_ri_1 {
						font-size: 24rpx;
					}

					.btm_ri_2 {
						font-size: 24rpx;
						font-weight: bold;
					}

					.btm_ri_3 {
						font-size: 30rpx;
						font-weight: bold;
					}

					.btm_ri_4 {
						font-size: 24rpx;
						font-weight: bold;
					}
				}
			}

			.operation_view {
				margin: 24rpx 24rpx 0;

				.operation_1 {
					width: 151rpx;
					height: 80rpx;
					border-radius: 16rpx;
					border: 2rpx solid #EEEEEE;
					font-weight: 400;
					font-size: 28rpx;
					color: #222222;

					image {
						width: 32rpx;
						height: 32rpx;
						margin-right: 10rpx;
					}
				}
			}
		}
	}

	.search_view {
		background: #FFFFFF;
		padding: 16rpx 24rpx 30rpx;
		border-radius: 0 0 16rpx 16rpx;

		.tabs {
			margin-bottom: 44rpx;

			.tabs_item {
				font-weight: 400;
				font-size: 30rpx;
				color: #333333;
				margin-right: 68rpx;
				position: relative;
			}

			.active_item {
				font-weight: bold;
				font-size: 38rpx;
				color: #222222;
			}

			.tabs_icon {
				width: 40rpx;
				height: 4rpx;
				background: #1A66FA;
				border-radius: 2rpx;
				position: absolute;
				bottom: -8rpx;
				left: 50%;
				transform: translateX(-50%);
			}
		}

		.search_input {
			width: 100%;
			height: 80rpx;
			border: 2rpx solid #EEEEEE;
			border-radius: 16rpx;
			position: relative;
			padding: 0 24rpx 0 78rpx;

			image {
				position: absolute;
				left: 28rpx;
				top: 50%;
				transform: translateY(-50%);
				width: 25rpx;
				height: 25rpx;
			}

			.input {
				font-size: 30rpx;
			}
		}
	}

	.personalInformation_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 16rpx 16rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 100rpx;
	}

	.personalInformation_picker2_0_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #BFBFBF;
	}

	.personalInformation_picker2_0_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
	}

	.personalInformation_picker2_0_c2 {
		color: rgba(44, 143, 255, 1);
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
	}

	.personalInformation_fd1_0 {
		// margin-top: 32rpx;
		height: 96rpx;
		border-top: 1px solid #eee;
	}

	.personalInformation_fd1_0_c0 {
		font-weight: 400;
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.6);
	}

	.personalInformation_fd1_0_c1_image {
		width: 72rpx;
		height: 72rpx;
		border-radius: 50%;
	}

	.personalInformation_fd1_1 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_1_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_1_c1 {
		font-weight: 400;
		font-size: 28rpx;
		color: #222222;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalInformation_fd1_2 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_2_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_2_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.personalInformation_fd1_3 {
		border-bottom: 1px solid #eee;
		height: 109rpx;
	}

	.personalInformation_fd1_3_c0 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.personalInformation_fd1_3_c1 {
		font-weight: 500;
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.8);
	}

	.personalInformation_flex_1 {
		background: #fff;
		border-radius: 16rpx;
		padding: 24rpx 24rpx 0rpx 24rpx;
		margin: 16rpx 24rpx 0;
	}

	.personalInformation_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.personalInformation_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #111;
	}

	.personalInformation_fd0_0_c1 {
		font-size: 32rpx;
		font-weight: bold;
		color: #111111;
	}

	.personalInformation_fd0_0_c2 {
		width: 36rpx;
		height: 36rpx;
	}

	.personalInformation_flex_0 {
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background: #fff;
		background-size: 100% auto !important;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: #f6f7fb;
		background-size: 100% auto !important;
	}
</style>